using System;
using System.IO;

using Ionic.Zip;

namespace octalforty.Componento.ComponentModel.Installation
{
    [ResourceInstaller(Priority = 100)]
    public class ZipFileResourceInstaller : IResourceInstaller
    {
        #region IResourceInstaller Members
        public bool CanInstall(Uri resourceUri)
        {
            return Path.GetExtension(resourceUri.LocalPath).ToLowerInvariant() == ".zip";
        }

        public void InstallResource(Uri resourceUri, string destinationPath)
        {
            Console.WriteLine("Installing from {0}", resourceUri);

            using(ZipFile zf = new ZipFile(resourceUri.LocalPath))
            {
                zf.ExtractAll(destinationPath, ExtractExistingFileAction.OverwriteSilently);
            } // using
        }
        #endregion
    }
}